/**
 * 
 */
package com.ld.tamp.web.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ld.tamp.web.bean.ComponentAccessToken;


/**
 * @author KeYang
 *
 */
@Component
public class ComponentAccessTokenDao {

	private static final String COMPONENT_ACCESS_TOKEN = "Component_Access_Token";

	@Autowired
	private RedisTemplate<String, String> redisTemplate;
	
	public void save(ComponentAccessToken token){
		
		redisTemplate.opsForValue().set(COMPONENT_ACCESS_TOKEN,JSON.toJSONString(token));
	}
	
	public ComponentAccessToken read(){
		String ticket = redisTemplate.opsForValue().get(COMPONENT_ACCESS_TOKEN);
		ComponentAccessToken token = JSON.parseObject(ticket,ComponentAccessToken.class);
		return token;
	}
}

